/*
 *--------------------------------------------------------------------------
 *   Battlefield - A Realtime Network Multiplayer Game
 *   =======================================================
 *   Developed by Group D02 - 2009/2010 Semester 4 - CS2103
 *     Harry Nguyen Duy Hoang <nnduyhoang@yahoo.co.uk>
 *     Kent Chng Siang Rong <fivefootway@gmail.com>
 *     Lim Yong Peng <limpeng1986@gmail.com>
 *     Loh Xiankun <u0807185@nus.edu.sg>
 *   Instructed by
 *     Dr. Damith C.Rajapakse <damith@gmail.com>
 *   =======================================================
 *   $Id: UnitManager.java 601 2010-07-26 18:46:36Z Harry $
 *   $LastChangedDate: 2010-07-26 18:46:36 +0000 (Mon, 26 Jul 2010) $
 *   $LastChangedBy: Harry $
 *--------------------------------------------------------------------------
 */
package battlefield.manager;

import battlefield.entity.Unit;
import battlefield.entity.UnitModel;
import battlefield.util.IDGenerator;
import java.util.HashMap;

/**
 *
 * @author Harry Nguyen
 */
public final class UnitManager extends HashMap<Integer, Unit> {

    private IDGenerator idGenerator;

    /**
     * Construct a UnitManager object that will manage all units created
     */
    public UnitManager() {
        idGenerator = new IDGenerator();
    }

    /**
     * Creates and returns a unit using a particular UnitModel
     * @param model
     * @return
     */
    public Unit create(UnitModel model) {
        Unit unit = new Unit(idGenerator.next(), model);
        put(unit.getId(), unit);
        return unit;
    }
}
